﻿using System;
using UnityEngine;
using XUpdater;
using XUtliPoolLib;

namespace XMainClient
{
	// Token: 0x02000B30 RID: 2864
	internal class XKeyboard : XSingleton<XKeyboard>
	{
		// Token: 0x17003011 RID: 12305
		// (get) Token: 0x0600A7AC RID: 42924 RVA: 0x001DB4F8 File Offset: 0x001D96F8
		public bool Enabled
		{
			get
			{
				return XSingleton<XUpdater.XUpdater>.singleton.EditorMode;
			}
		}

		// Token: 0x17003012 RID: 12306
		// (get) Token: 0x0600A7AD RID: 42925 RVA: 0x001DB514 File Offset: 0x001D9714
		public int touchCount
		{
			get
			{
				return this._touch_count_this_frame;
			}
		}

		// Token: 0x0600A7AE RID: 42926 RVA: 0x001DB52C File Offset: 0x001D972C
		public XKeyboard()
		{
			for (int i = 0; i < XTouch.MultiTouchCount; i++)
			{
				this._touches[i] = new XTouchItem();
			}
		}

		// Token: 0x0600A7AF RID: 42927 RVA: 0x001DB5A4 File Offset: 0x001D97A4
		public XTouchItem GetTouch(int idx)
		{
			return this._touches[idx];
		}

		// Token: 0x0600A7B0 RID: 42928 RVA: 0x001DB5C0 File Offset: 0x001D97C0
		public void Update()
		{
			this._touch_count_this_frame = 0;
			this._bAxis = false;
			if (Input.GetMouseButton(0))
			{
				this._touches[this._touch_count_this_frame].faketouch.fingerId = XFastEnumIntEqualityComparer<XFingerId>.ToInt(XFingerId.XCommon_0);
				this._touches[this._touch_count_this_frame].faketouch.position = Input.mousePosition;
				this._touches[this._touch_count_this_frame].faketouch.deltaTime = Time.smoothDeltaTime;
				this._touches[this._touch_count_this_frame].faketouch.deltaPosition = Input.mousePosition - this._lastMousePos;
				this._touches[this._touch_count_this_frame].faketouch.phase = (Input.GetMouseButtonDown(0) ? TouchPhase.Began : ((this._touches[this._touch_count_this_frame].faketouch.deltaPosition.sqrMagnitude > 1f) ? TouchPhase.Moved : TouchPhase.Stationary));
				this._touches[this._touch_count_this_frame].faketouch.tapCount = 1;
				this._touches[this._touch_count_this_frame].Fake = true;
				this._lastMousePos = Input.mousePosition;
				this._touch_count_this_frame++;
			}
			else
			{
				if (Input.GetMouseButtonUp(0))
				{
					this._touches[this._touch_count_this_frame].faketouch.fingerId = XFastEnumIntEqualityComparer<XFingerId>.ToInt(XFingerId.XCommon_0);
					this._touches[this._touch_count_this_frame].faketouch.position = Input.mousePosition;
					this._touches[this._touch_count_this_frame].faketouch.deltaTime = Time.smoothDeltaTime;
					this._touches[this._touch_count_this_frame].faketouch.phase = TouchPhase.Ended;
					this._touches[this._touch_count_this_frame].faketouch.tapCount = 1;
					this._touches[this._touch_count_this_frame].Fake = true;
					this._touch_count_this_frame++;
				}
			}
			this._bAxis = true;
			int num = 0;
			int num2 = 0;
			if (Input.GetKey(KeyCode.A))
			{
				num--;
			}
			if (Input.GetKey(KeyCode.D))
			{
				num++;
			}
			if (Input.GetKey(KeyCode.S))
			{
				num2--;
			}
			if (Input.GetKey(KeyCode.W))
			{
				num2++;
			}
			if (num != 0 || num2 != 0)
			{
				this._touches[this._touch_count_this_frame].faketouch.fingerId = XFastEnumIntEqualityComparer<XFingerId>.ToInt(XFingerId.XCommon_1);
				this._touches[this._touch_count_this_frame].faketouch.deltaTime = Time.smoothDeltaTime;
				this._touches[this._touch_count_this_frame].faketouch.phase = ((this._x == 0f && this._y == 0f) ? TouchPhase.Began : TouchPhase.Moved);
				this._touches[this._touch_count_this_frame].faketouch.position = ((this._touches[this._touch_count_this_frame].faketouch.phase == TouchPhase.Began) ? new Vector2(XSingleton<XVirtualTab>.singleton.MaxDistance, XSingleton<XVirtualTab>.singleton.MaxDistance) : ((num != 0 && num2 != 0) ? new Vector2(XSingleton<XVirtualTab>.singleton.MaxDistance + (float)num * XSingleton<XVirtualTab>.singleton.MaxDistance * 0.707f, XSingleton<XVirtualTab>.singleton.MaxDistance + (float)num2 * XSingleton<XVirtualTab>.singleton.MaxDistance * 0.707f) : new Vector2(XSingleton<XVirtualTab>.singleton.MaxDistance + (float)num * XSingleton<XVirtualTab>.singleton.MaxDistance, XSingleton<XVirtualTab>.singleton.MaxDistance + (float)num2 * XSingleton<XVirtualTab>.singleton.MaxDistance)));
				this._touches[this._touch_count_this_frame].faketouch.tapCount = 1;
				this._touches[this._touch_count_this_frame].Fake = true;
				this._touch_count_this_frame++;
			}
			else
			{
				if (this._x != 0f || this._y != 0f)
				{
					this._touches[this._touch_count_this_frame].faketouch.fingerId = XFastEnumIntEqualityComparer<XFingerId>.ToInt(XFingerId.XCommon_1);
					this._touches[this._touch_count_this_frame].faketouch.position = new Vector2(XSingleton<XVirtualTab>.singleton.MaxDistance, XSingleton<XVirtualTab>.singleton.MaxDistance);
					this._touches[this._touch_count_this_frame].faketouch.deltaTime = Time.smoothDeltaTime;
					this._touches[this._touch_count_this_frame].faketouch.phase = TouchPhase.Ended;
					this._touches[this._touch_count_this_frame].faketouch.tapCount = 1;
					this._touches[this._touch_count_this_frame].Fake = true;
					this._touch_count_this_frame++;
				}
			}
			this._x = (float)num;
			this._y = (float)num2;
			if (!this._bAxis)
			{
				this._x = 0f;
				this._y = 0f;
			}
		}

		// Token: 0x04003E0A RID: 15882
		private XTouchItem[] _touches = new XTouchItem[XTouch.MultiTouchCount];

		// Token: 0x04003E0B RID: 15883
		private int _touch_count_this_frame = 0;

		// Token: 0x04003E0C RID: 15884
		private bool _bAxis = false;

		// Token: 0x04003E0D RID: 15885
		private float _x = 0f;

		// Token: 0x04003E0E RID: 15886
		private float _y = 0f;

		// Token: 0x04003E0F RID: 15887
		private Vector3 _lastMousePos = Vector3.zero;
	}
}
